import { merge } from "lodash-es";
import { mapStore } from "../../utils/store";
import { $http } from "../../boot/http";
export default merge(
  {
    namespaced: true,
    state: {},
    mutations: {},
    getters: {},
    actions: {
      // 获取矿机详情
      async getGoodInfo({ dispatch }, params) {
        return dispatch(
          "toggleLoading",
          {
            key: "shop.good_info",
            loading: async () => {
              const { data } = await $http.get(
                "m/mfc/api/goods/info",
                params
              );
              console.log(data)
              return data;
            }
          },
          {
            root: true
          }
        );
      },
      // 购买在售商品
      async buyGood({ dispatch }, params) {
        return dispatch(
          "toggleLoading",
          {
            key: "shop.goods_buy",
            loading: async () => {
              const { data } = await $http.post(
                "m/mfc/api/goods/buy",
                params
              );
              return data
            }
          },
          {
            root: true
          }
        );
      },
      // 购买转让订单 
      async buyOrder({ dispatch }, params) {
        return dispatch(
          "toggleLoading",
          {
            key: "shop.goods_buy",
            loading: async () => {
              const { data } = await $http.post(
                "m/mfc/api/order/buy_in",
                params
              );
            }
          },
          {
            root: true
          }
        );
      },
      // 获取算力包信息 
      async suanliInfo({ dispatch }, params) {
        return dispatch(
          "toggleLoading",
          {
            key: "shop.suanli_info",
            loading: async () => {
              const { data } = await $http.get(
                "m/mfc/api/suanlibao/info",
                params
              );
              return data;
            }
          },
          {
            root: true
          }
        );
      },
      // 算力宝购买支付
      async buySuanlibao({ dispatch }, params) {
        return dispatch(
          "toggleLoading",
          {
            key: "shop.suanlibao_buy",
            loading: async () => {
              const { data } = await $http.post(
                "m/mfc/api/suanlibao/buy",
                params
              );
            }
          },
          {
            root: true
          }
        );
      },
      // 赎回算力宝
      async redeemSuanlibao({ dispatch }, params) {
        return dispatch(
          "toggleLoading",
          {
            key: "shop.suanlibao_buy",
            loading: async () => {
              const { data } = await $http.post(
                "m/mfc/api/suanlibao/redeem",
                params
              );
              return data
            }
          },
          {
            root: true
          }
        );
      },
      // 获取M币价格
      async mfcPrice({ dispatch }, params) {
        return dispatch(
          "toggleLoading",
          {
            key: "shop.mfc_price",
            loading: async () => {
              const { data } = await $http.get(
                "m/mfc/api/mfc_price",
                params
              );
              return data
            }
          },
          {
            root: true
          }
        );
      },
    }
  },
  // 获取矿机列表
  mapStore("goodsList", {
    url: "m/mfc/api/goods/index",
    options: {
      actionOptions: {
        commitType: "infinite"
      }
    },
    loadingKey: "mf.shop.goods_list"
  }),
  // c2c转让市场
  mapStore("orderMarket", {
    url: "m/mfc/api/order/market",
    options: {
      actionOptions: {
        commitType: "infinite"
      }
    },
    loadingKey: "mf.shop.order_market"
  }),
  // 获取质押宝列表 m/mfc/api/suanlibao/index
  mapStore("suanlibaoList", {
    url: "m/mfc/api/suanlibao/index",
    options: {
      actionOptions: {
        commitType: "infinite"
      }
    },
    loadingKey: "mf.shop.suanlibao_list"
  }),
  // 获取算力宝订单列表
  mapStore("orderListSuanli", {
    url: "m/mfc/api/suanlibao/order",
    options: {
      actionOptions: {
        commitType: "infinite"
      }
    },
    loadingKey: "mf.shop.suanlibao_order_list"
  }),
);
